<!--{include(file='head.html')}-->
<script type="text/javascript" src="template/jslib/date/WdatePicker.js"></script>
<script type="text/javascript" src="template/jslib/tbox/tbox.js"></script>
<link rel="stylesheet" href="template/jslib/tbox/tbox.css" type="text/css" />
<div id="wrap">
	<!--{include('left.html')}-->
	<div id="maincont">
		<b class="b1"></b><b class="b2"></b><b class="b3"></b><b class="b4"></b>
		<div id="main_c">
			<form name="seaform" id="seaform" action="<!--{url('admin','trade','index')}-->" method="post" onsubmit="$.oper.checkq('submit')">
				<div class="bt_bk">
					<span class="btn">
						<a href="javascript:void(0);" onclick="$.oper.refresh();return false;">刷新</a>
						<a href="javascript:void(0);" onclick="$.oper.remove();return false;">移除</a>
					</span>
					<span class="search_bk">
						从 <input type="text" class="input_tx short" value="<!--{if $time1}--><!--{date('Y-m-d H:i',$time1)}--><!--{/if}-->" name="time1" onclick="WdatePicker()" id="time1"/>
						到 <input type="text" class="input_tx short" value="<!--{if $time2}--><!--{date('Y-m-d H:i',$time2)}--><!--{/if}-->" name="time2" onclick="WdatePicker()" id="time2"/>
						<select name="qtype" class="select_tx">
							<option value="trade"		<!--{if $qtype == 'trade'}-->selected<!--{/if}-->	>订单</option>
							<option value="user"		<!--{if $qtype == 'user'}-->selected<!--{/if}-->	>会员</option>
							<option value="receiver"	<!--{if $qtype == 'receiver'}-->selected<!--{/if}-->>收货人</option>
						</select>
						<input type="text" class="input_tx <!--{if !$q}-->hintinput<!--{/if}-->" name="q" id="q" 
								value="<!--{def($q,'订单编号/会员（ID）/收货人')}-->" 
								onfocus="$.oper.checkq('focus')" onblur="$.oper.checkq('blur')"/>
						<input type="hidden" value="" name="do" id="do"/>
						<input type="button" value="搜索" class="input_bt" onclick="$.oper.seasubmit('sea')"/>
						<input type="button" value="导出" class="input_bt" onclick="$.oper.seasubmit('import')"/>
					</span>
					<span class="state_tip"></span>
				</div>
				<input type="hidden" value="<!--{def($pagearr['page'],1)}-->"		name="page" id="page"/>
				<input type="hidden" value="<!--{def($pagearr['pagesize'],10)}-->"	name="pagesize" id="pagesize" />
				<input type="hidden" value="<!--{$type}-->" name="type" id="type"/>
				<input type="hidden" value="<!--{$ordertime}-->" name="ordertime" id="ordertime"/>
			</form>
			<!--{include_page("page.html","top")}-->
			<div class="sn3">
				<select name="chgtime" onchange="seasubmit('ordertime',this.value)">
					<option value="0"  <!--{if !$ordertime}-->selected<!--{/if}-->>全部</option>
					<option value="30" <!--{if $ordertime == 30}-->selected<!--{/if}-->	>30天以内的订单</option>
					<option value="40" <!--{if $ordertime == 40}-->selected<!--{/if}--> >更早的订单</option>
				</select>
			</div>
			<div class="sn2">
				<a href="javascript:void(0)" id="a_all"		onclick="seasubmit('type','all');return false;"		
				<!--{if $type == "all"}-->class='on'<!--{/if}-->>全部</a>
				<a href="javascript:void(0)" id="a_wait_pay"		onclick="seasubmit('type','wait_pay');return false;"		
				<!--{if $type == "wait_pay"}-->class='on'<!--{/if}-->>未支付</a>
				<a href="javascript:void(0)" id="a_wait_send"		onclick="seasubmit('type','wait_send');return false;"		
				<!--{if $type == "wait_send"}-->class='on'<!--{/if}-->>待发货</a>
				<a href="javascript:void(0)" id="a_wait_rece"	onclick="seasubmit('type','wait_rece');return false;"		
				<!--{if $type == "wait_rece"}-->class='on'<!--{/if}-->>已发货</a>
				<a href="javascript:void(0)" id="a_finish"	onclick="seasubmit('type','finish');return false;"	
				<!--{if $type == "finish"}-->class='on'<!--{/if}-->>已完成</a>
				<a href="javascript:void(0)" id="a_cancel"	onclick="seasubmit('type','cancel');return false;"	
				<!--{if $type == "cancel"}-->class='on'<!--{/if}-->>已作废</a>
			</div>
			<table class="tableStyle" border="0" cellspacing="0" cellpadding="0">
				<thead>
					<tr align="center">
						<th width="5%">
							<input type="checkbox" value="1" name="allselect" id="allselect" autocomplete="off" onclick="$.oper.selectall()"/>
						</th>
						<th width="15%">操作</th>
						<th width="10%" nowrap>订单编号</th>
						<th width="25%">商品</th>
						<th width="20%">收货人</th>
						<th width="10%">状态</th>
						<th width="5%" nowrap>金额(￥)</th>
						<th width="10%">下单时间</th>
					</tr>
				</thead>
				<tbody id="listtbody">
					<!--{foreach $trades trade}-->
					<tr align="center" id="tr_<!--{$trade.tradeid}-->">
						<td><input type="checkbox" value="<!--{$trade.tradeid}-->" name="singleselect" autocomplete="off"/></td>
						<td>
							<a href="javascript:void(0);" onclick="$.oper.remove('<!--{$trade.tradeid}-->');return false;" class="remove"  title="移除"></a>
							<a href="javascript:void(0)"  onclick="Trade.view('<!--{$trade.tradeid}-->');return false;" class="detail"  title="详情"></a>
<a href="<!--{url('admin','trade','tradeoper','opertype=pttrade&tradeid=$trade[tradeid]')}-->" class="pttrade"  title="打印购物单" target="_blank"></a>
<a href="<!--{url('admin','trade','tradeoper','opertype=ptsend&tradeid=$trade[tradeid]')}-->"	class="ptsend"  title="打印配送单" target="_blank"></a>
<a href="<!--{url('admin','trade','tradeoper','opertype=ptexpress&tradeid=$trade[tradeid]')}-->" class="ptexpress"  title="打印快递单" target="_blank"></a>
						</td>
						<td class="row_actions">
							<div><!--{$trade.tradeid}--></div>
							<p style="visibility:hidden;">
								<!--{if strtolower($trade['status']) == 'wait_pay'}-->
								<span>
									<a href="javascript:void(0)" onclick="Trade.editfee('<!--{$trade.tradeid}-->');return false;">改价</a> 
								</span>
								<span>
									<a href="javascript:void(0)" onclick="Trade.pay('<!--{$trade.tradeid}-->');return false;">支付</a> 
								</span>
								<span>
									<a href="javascript:void(0)" onclick="Trade.send('<!--{$trade.tradeid}-->');return false;">发货</a> 
								</span>
								<span>
									<a href="javascript:void(0)" onclick="Trade.finish('<!--{$trade.tradeid}-->');return false;">完成</a>  
								</span>
								<span>
									<a href="javascript:void(0)" onclick="Trade.cancel('<!--{$trade.tradeid}-->');return false;">作废</a> 
								</span>
								<!--{elseif strtolower($trade['status']) == 'wait_send'}-->
								<span>
									<a href="javascript:void(0)" onclick="Trade.send('<!--{$trade.tradeid}-->');return false;">发货</a> 
								</span>
								<span>
									<a href="javascript:void(0)" onclick="Trade.finish('<!--{$trade.tradeid}-->');return false;">完成</a>
								</span>
								<span>
									<a href="javascript:void(0)" onclick="Trade.cancel('<!--{$trade.tradeid}-->');return false;">作废</a> 
								</span>
								<!--{elseif strtolower($trade['status']) == 'wait_rece'}-->
									<!--{if $kuaidi_status}-->
								<span>
									<a href="javascript:void(0)" onclick="Trade.kuaidi('<!--{$trade.tradeid}-->');return false;">物流</a>
								</span>
									<!--{/if}-->
								<span>
									<a href="javascript:void(0)" onclick="Trade.finish('<!--{$trade.tradeid}-->');return false;">完成</a>
								</span>
								<span>
									<a href="javascript:void(0)" onclick="Trade.cancel('<!--{$trade.tradeid}-->');return false;">作废</a> 
								</span>
								<!--{/if}-->
							</p>
						</td>
						<td align="left">
							<!--{foreach $trade['order'] order}-->
							<a href="<!--{url('index','item','index','itemid=$order[itemid]')}-->" class="tradeimg" target="_blank" title="<!--{$order['itemname']}-->">
								<img src="<!--{$order['itemimg']}-->_50x50.jpg" width="50" height="50" />
							</a>
							<!--{/foreach}-->
						</td>
						<td align="left">
							<!--{$trade.receiver_name}-->[<!--{$trade.receiver_link}-->]<br />
							<!--{getDistrict($trade.receiver_province,$trade.receiver_city,$trade.receiver_district)}--><!--{$trade.receiver_address}-->
						</td>
						<td align="left" nowrap>状态：<!--{getCommonCache('$trade[status]','tradestatus')}--><br />
							支付：<!--{getCommonCache('$trade[payment]','payment')}-->
						</td>
						<td align="left" nowrap>
							商品：<!--{getPrice($trade.itemfee)}--><br />
							物流：<!--{getPrice($trade.postfee)}--><br />
							结算：<!--{getPrice($trade.totalfee)}-->
						</td>
						<td><!--{date("m月d日 H:i",$trade[addtime])}--></td>
					</tr>
					<!--{/foreach}-->
				</tbody>
			</table>
			<!--{include_page("page.html","foot")}-->
		</div>
		<b class="b4b"></b><b class="b3b"></b><b class="b2b"></b><b class="b1b"></b>
	</div>
</div>
<!--{include(file='foot.html')}-->
<script type="text/javascript">
$(function(){
	$.oper.init("<!--{url('admin','trade','tradeoper')}-->").setdefq('订单编号/会员（ID）/收货人');
	$(".row_actions").mouseover(function(){
		$(this).find("p").css({"visibility":"visible"});
	}).mouseout(function(){
		$(this).find("p").css({"visibility":"hidden"});
	});
});
var Trade = {
	url	: "<!--{url('admin','trade','tradeoper')}-->",
	finish : function(tradeid) {
		var _this = this;
		jConfirm("确认完成？","确认完成",function(confirm){
			if(confirm){
				_this.post(tradeid,'finish');
			}
		})
	},
	cancel:function(tradeid) {
		var _this = this;
		jConfirm("确认作废？","确认作废",function(confirm){
			if(confirm){
				_this.post(tradeid,'cancel');
			}
		})
	},
	post:function(tradeid,opertype,otherpara) {
		var postdata = {tradeid:tradeid,opertype:opertype};
		if(otherpara) $.extend(postdata,otherpara);
		$.post(this.url,postdata,function(data) {
			if(data == "success") {
				jAlert("操作成功!","提示");
				$.oper.refresh();
			} else {
				jAlert(data);
			}
		});
	},
	editfee:function(tradeid) {
		$.tbox.popup(this.url,"GET",{opertype:'editfee',tradeid:tradeid});
	},
	editfeeok:function(tradeid) {
		var _this = this;
		var totalfee			= parseFloat($("#totalfee").val()) || 0,
			editfeememo		= $("#editfeememo").val();
		if(!totalfee) {
			jAlert("请填写最终结算！");
			return false;
		}
		if(!editfeememo) {
			jAlert("请填写改价备注！");
			return false;
		}
		var opt = {totalfee:totalfee,editfeememo:editfeememo};
		jConfirm("确认改价？","确认改价",function(confirm){
			if(confirm){
				_this.post(tradeid,'editfeeok',opt);
			}
		});
	},
	pay:function(tradeid) {
		$.tbox.popup(this.url,"GET",{opertype:'pay',tradeid:tradeid});
	},
	payok:function(tradeid) {
		var _this = this;
		jConfirm("确认支付？","确认支付",function(confirm){
			if(confirm){
				_this.post(tradeid,'payok');
			}
		})
	},
	send:function(tradeid) {
		$.tbox.popup(this.url,"GET",{opertype:'send',tradeid:tradeid});
	},
	sendok:function(tradeid) {
		var _this = this;
		jConfirm("确认发货？","确认发货",function(confirm){
			if(confirm){
				var sendno = $.trim($("#sendno").val());
				if(!sendno) {
					alert("请输入快递单号！");
					return false;
				}
				var opt = {sendno:sendno,companyid:$("#companyid").val()}
				_this.post(tradeid,'sendok',opt);
			}
		})
	},
	kuaidi:function(tradeid) {
		$.tbox.popup(this.url,"GET",{opertype:"kuaidi",tradeid:tradeid});
	},
	view:function(tradeid) {
		$.tbox.popup(this.url,"GET",{opertype:'view',tradeid:tradeid});
	}
}
function seasubmit(field,value) {
	$("#"+field).val(value);
	if(field == "ordertime") {
		$("#time1,#time2").val('');
	}
	$("#seaform").submit();
}
</script>